package cn.zhujs.org.service.impl;

import cn.zhujs.org.domain.Department;
import cn.zhujs.org.mapper.DepartmentMapper;
import cn.zhujs.org.query.DepartmentQuery;
import cn.zhujs.org.service.IDepartmentService;
import cn.zhujs.util.PageList;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService{
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    @Transactional
    public void add(Department department) {
        departmentMapper.save(department);
    }

    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    @Transactional
    public void remove(Long id) {
         departmentMapper.delete(id);
    }

    @Override
    public Department queryById(Long id) {
        return departmentMapper.loadById(id);
    }

    @Override
    public List<Department> queryAll() {
        return departmentMapper.loadAll();
    }

    @Override
    public PageList<Department> queryPage(DepartmentQuery query) {
        Long total=departmentMapper.queryCount(query);
        List<Department>data=departmentMapper.queryData(query);
        return new PageList<>(total,data);
    }
}
